home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5720 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  62 lines

  1. Newsgroups: comp.lang.c
  2. Path: cs.dal.ca!ug!mzhang
  3. From: mzhang@ug.cs.dal.ca (MAONI ZHANG)
  4. Subject: Mastermind 
  5. Message-ID: <Dn4EwB.Kow@cs.dal.ca>
  6. Sender: usenet@cs.dal.ca (USENET News)
  7. Nntp-Posting-Host: ug.cs.dal.ca
  8. Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. Date: Wed, 21 Feb 1996 10:09:45 GMT
  11.  
  12. Hello All,
  13.  
  14. I can't figure out a good way to programm mastermind, here's the description 
  15. of it:
  16.  
  17. /* beginning of the description */
  18.  
  19. Mastermind is a popular children's game. One player is the "codemaker"
  20. M who chooses a code represented by four coloured pegs. The other
  21. player is the "code-breaker" B who is allowed up to 10 guesses at the
  22. code. B wins if (s)he guesses the code within 10 trys otherwise M wins.
  23. It may also be interesting to keep track of statistics on the number of
  24. guesses required.
  25.  
  26. After each guess M reports a score which contains partial information.
  27. The score has two parts, viz, the number of exact matches and the
  28. number of matches in the wrong position. It helps to consider an
  29. example. Suppose the secret code is (Red White Black Black) and B
  30. guesses (Black Black Red Black).  The score in this case would be one
  31. exact match (the fourth position) and two "other" matches (the first
  32. Black and the third Red in the guess). Note that no coloured peg in the
  33. code can match more than one position in the guess and so the second
  34. Black in the guess has nothing left to match with after the other
  35. matches have been paired off. Scoring is surprisingly difficult for
  36. human players and both players must be adept at it.
  37.  
  38. The question of what strategy he codebreaker B should use to pick
  39. guesses is very interesting. One strategy for B is to consider
  40. all possible guesses and to reject those that are inconsistent
  41. with previous guesses. An consistent guess is one which when
  42. scored against all previous gives the same scores. For example,
  43. after receiving a score of (1 2) for (Black Black Red Black) the guess
  44. (Black Red Black Red) is consistent (scored against (Black Black
  45. Red Black) it would get a score of (1 2)). Most other possible
  46. guesses would be inconsistent and rejected by player B.
  47.  
  48. /* end of the description */
  49.  
  50. The first guess would be repeating the 1st color of the 6 colors(suppose 
  51. we need to guess 4 outta 6) for 4 times.
  52.  
  53.  
  54. I couldn't think of a good algorithm to do it. it need to be done in c/c++.
  55.  
  56.  
  57. Please email me at mzhang@ug.cs.dal.ca if you get any idea. Thanks for any
  58. suggestions.
  59.  
  60.  
  61. -Maoni
  62.